﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>

        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
</head>
<body>

<div class="newtest">

    <div class="container new_serach">
        <a class="btn btn-primary btn-sm" href="{:URL('community/Article/index')}">分类管理</a>
        <a class="btn btn-primary btn-sm" href="{:URL('community/Article/tag')}">标签管理</a>
    </div>

    <div class="container new_serach">

        <span> 景区名称：</span>
        <div class="layui-inline layui-form"  >
            <select name="colony_id" lay-filter="colony_id" lay-search="">
                <option value="0" > 请选择 </option>
                {volist name="community" id="vo"}
                <option value="{$vo.id}" {if condition="$colony_id eq $vo['id']"} selected {/if}> {$vo.name} </option>
                {/volist}
            </select>
        </div>

        <span> 标签名称：</span>
        <div class="layui-inline">
            <input class="form-control serach_key" name="name" value="{$name}" type="text">
        </div>
        <span> 状态：</span>
        <div class="layui-inline layui-form"  style="width:80px;">
            <select name="status" lay-filter="status">
                <option value="0" {if condition="$status eq 0"} selected {/if}>全部</option>
                <option value="1" {if condition="$status eq 1"} selected {/if}>启用</option>
                <option value="2" {if condition="$status eq 2"} selected {/if}>禁用</option>
            </select>
        </div>
        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>

    </div>

    <div class="new_main">
        <table class="layui-hide" id="demo" lay-filter="demo"></table>
        <script type="text/html" id="barDemo">
            <a class="btn-sm btn-primary" lay-event="js_update">修改</a>
            <a class="btn-sm btn-danger" lay-event="del">删除</a>
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a class="layui-btn-sm layui-btn" lay-event="add_btn">添加标签</a>
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">批量删除</button>
            </div>
        </script>

        <script type="text/html" id="switchTpl">
            <!--启用禁用操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>
    </div>
</div>


</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<script>
    var modal = new yii.modal();
    layui.use(['form', 'jquery', 'layer', 'laydate','table'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        var colony_id = 0;
        form.on('select(colony_id)',function (data) {
            colony_id = data.value;
        });
        var status = 0;
        form.on('select(status)',function (data) {
            status = data.value;
        });

        //搜索操作
        $('.layui-btn').click(function () {
            var name = $('input[name="name"]').val();
            table.reload('demo', {
                url:"{:URL('community/article/tag')}"
                // ,methods:"post"
                , request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , where: {
                    colony_id: colony_id,
                    name: name,
                    status:status,
                }
                , page: {
                    curr: 1
                }
            });
        });

        table.render({
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            elem: '#demo', // 表格id
            url:"{:URL('community/article/tag')}",
            where:{type:'list'},
            title: '单元列表',
            page: true, // 树形表格一般是没有分页的
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
                ,{field: 'name', title: '标签名称', align:'center'}
                ,{field: 'propertyName', title: '关联景区', align:'center'}
                ,{field: 'sort', title: '排序', align:'center',edit: 'number',width:60}
                ,{field: 'status', title: '状态',templet: '#switchTpl', unresize: true, align:'center'}
                ,{fixed: 'right',title: '操作', width:220, align:'center', toolbar: '#barDemo'}
            ]],
            done: function() {
                layer.closeAll('loading');
            }
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            if (state == true) {
                //上线
                updateProductStatus(id,'1');
            } else {
                //下线
                updateProductStatus(id,'2');
            }
        });
        //监听单元格编辑
        table.on('edit(demo)', function(obj){
            var value = obj.value; //得到修改后的值
            var id = obj.data.id;
            $.ajax({
                type: "post",
                url: "/common/Common/updateSort",
                data: {id: id,table:'community_article_tag',value:value},
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }
                }
            });
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj) {
            switch (obj.event) {
                case 'del':
                    var id = obj.data.id;
                    layer.confirm('是否确定操作?', function (index) {
                        delOperation(id, obj, index);
                    });
                    break;
                case 'js_update':
                    var id = obj.data.id;
                    modal.initialization({
                        url: "{:URL('community/article/addTag')}",
                        type: "post",
                        data:{
                            type:'detail',
                            id:id
                        }
                    });
                    break;
            }
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].id;
                    }
                    if(id.length==0){
                        layer.alert("请选择需操作的数据");return;
                    }
                    layer.confirm('是否确定操作?', function(index){
                        delOperation(id,obj,index,1);
                    });
                    break;
                case 'add_btn':
                    modal.initialization({
                        url: "{:URL('community/article/addTag')}",
                        type: "post",
                        data:{
                            type:'detail'
                        }
                    });
                    break;

            };
        });


        //删除
        function delOperation(id,obj,index,reload=0) {
            $.ajax({
                type: "post",
                url: "{:URL('community/article/delTag')}",
                data: {id:id},
                dataType: "json",
                success: function(data){
                    layer.alert(data.msg);
                    if(data.code==0){
                        if(reload==0){
                            obj.del();
                            layer.close(index);
                        }else{
                            //执行重载
                            table.reload('demo');
                            layer.close(index);
                        }
                    }
                }
            });
        }


    });




    //更改状态
    function updateProductStatus(id,status) {
        $.ajax({
            type: "post",
            url: "{:URL('common/together/clickStatus')}",
            data: {id:id,status:status,table:'community_article_tag'},
            dataType: "json",
            success: function(data){}
        });
    }


</script>

</html>
